package com.personnalManagerSystem.util;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @Author liqing
 * @Date: 2022/3/27 13:03
 * @Description  工具类自动生成实体类控制类等
 */
public class MybatisPlusUtil {
    public static void main(String[] args) {
        String userDir = System.getProperty("user.dir");
        System.out.println("userDir=" + userDir);
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        //获取当前的项目的路径
        String projectPath = System.getProperty("user.dir");
        System.out.println(projectPath);
        //配置生成路径
        gc.setOutputDir(projectPath + "/src/main/java");
        // 作者名称
        gc.setAuthor("liqing");
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        mpg.setGlobalConfig(gc);
        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/personnalManagerSystem?userUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=GMT");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        mpg.setDataSource(dsc);
        // 包配置
        PackageConfig pc = new PackageConfig();
        //设置父级的包
        pc.setParent("com.personnalManagerSystem");
//        pc.setController("controller");
        pc.setEntity("model");
//        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);
        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();
        templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);
        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        //表名
        strategy.setInclude("company_income");
        strategy.setControllerMappingHyphenStyle(true);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        mpg.setStrategy(strategy);
        //mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
}
